package jwanalytics.dbloader;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


import org.apache.log4j.Logger;


/**
 * Administrative utilities to change your jwanalytics dimensional model database.  To use run the main method
 * which will prompt you with a menu of choices.  For those of you developing with jwanalytics the "1.
 * Delete parts of database sub menu options" will be specially useful because it allows to clean the database 
 * from runtime generated entries while not deleting the dimension tables which are constant (date_dimension,
 * time_of_day_dimension), etc.
 * 
 * Be careful with "2. Recreate database" as it does what the name says.  It will delete your entire database,
 * including sequences and recreate it.
 * 
 * A pre-requisite to run this class is having a well configured database on your jwanalytics.properties.
 * 
 * @see 
 * jwanalytics.dbloader.PopulateDateDimension, jwanalytics.dbloader.PopulateTimeOfDayDimension, 
 * jwanalytics.dbloader.RecreateDatabase.
 * 
 * @author CestaA
 */
public class AdminUtilities {
	
	/** Logger errors. */
	public static Logger logger = Logger.getLogger("jwanalytics");
	
	/** See class javadoc. */
	public static void main(String[] args) {
		Props.init(Props.PROPS_FILE, false);
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String answer = null;
		while (true) {
			answer = null;
			// TODO Auto-generated method stub
			System.out.println("Choose an option:");
			System.out.println("1. Delete parts of database sub menu options.");
			System.out.println("2. Recreate database.");
			System.out.println("3. Exit.");			
			try {
				answer = br.readLine();
			} catch (IOException e) {
				logger.error("WAERROR0037:"+e);
				if (logger.isDebugEnabled()) e.printStackTrace();
			}
			System.out.println("Your answer was:"+answer);
			if (answer == null) continue;
			if (answer.toUpperCase().indexOf("1") != -1) {
				DeletePartsOfDatabase.main(args);
			} else if (answer.toUpperCase().indexOf("2") != -1) {
				RecreateDatabase.main(args);
			} else if (answer.toUpperCase().indexOf("3") != -1) {
				break;
			} 
		}
	}
	
	
}